package com.sfac.javaSpringBoot.modules.account.controller;

import com.github.pagehelper.PageInfo;
import com.sfac.javaSpringBoot.modules.account.entity.Resource;
import com.sfac.javaSpringBoot.modules.account.service.ResourceService;
import com.sfac.javaSpringBoot.modules.common.entity.Result;
import com.sfac.javaSpringBoot.modules.common.entity.SearchBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ResourceController {

//    @Autowired
//    ResourceService resourceService;
//
////    127.0.0.1/resource/insertResources
////    [{"permit":"/api/user/"},{"permit":"/api/role/"}]
//    @PostMapping(value = "/resource",consumes = "application/json")
//    public Result<Resource> insertUsers(@RequestBody List<Resource> resource){
//        return resourceService.insertResource(resource);
//    }
////    127.0.0.1/resource/deleteResource/2
//    @DeleteMapping(value = "/resource/{id}")
//    Result<Resource> deleteResource(@PathVariable int id) {
//        return resourceService.deleteResource(id);
//    }
////    127.0.0.1/resource/editResource
////     {"id":2},{"permit":"/api/Role/"}
//    @PutMapping(value = "/resource",consumes = "application/json")
//     public Result<Resource> editResource(@RequestBody Resource resource){
//        return resourceService.editResource(resource);
//    }
////    127.0.0.1/resource/getAllResource
//    @GetMapping(value = "/getAllResource")
//    public  List<Resource> getAllResource(){
//        return resourceService.getAllResource();
//    }
//
////    127.0.0.1/resource/getResourceById/3
//    @GetMapping(value = "/getResourceById/{id}")
//    public  Resource getResourceById(@PathVariable int id){
//     return resourceService.getResourceById(id);
//    }
//    /**
//     * 127.0.0.1/api/resources ---- post
//     * {"currentPage":"1","pageSize":"5","orderBy":"id","direction":"desc","keyWord":""}
//     */
//    @PostMapping(value = "/resources", consumes = "application/json")
//    public PageInfo<Resource> getResourcesBySearchBean(@RequestBody SearchBean searchBean) {
//        return resourceService.getResourcesBySearchBean(searchBean);
//    }




//    老师代码
@Autowired
private ResourceService resourceService;

    /**
     * 127.0.0.1/api/resource ---- post
     * {"permission":"deleteUser"}
     */
    @PostMapping(value = "/resource", consumes = "application/json")
    public Result<Resource> insertResource(@RequestBody Resource resource) {
        return resourceService.insertResource(resource);
    }

    /**
     * 127.0.0.1/api/resource ---- put
     * {"id":"1","permission":"deleteUser"}
     */
    @PutMapping(value = "/resource", consumes = "application/json")
    public Result<Resource> updateResource(@RequestBody Resource resource) {
        return resourceService.updateResource(resource);
    }

    /**
     * 127.0.0.1/api/resource/2 ---- delete
     */
    @DeleteMapping("/resource/{id}")
    public Result<Object> deleteResourceById(@PathVariable int id) {
        return resourceService.deleteResourceById(id);
    }

    /**
     * 127.0.0.1/api/resource/1 ---- get
     */
    @GetMapping("/resource/{id}")
    public Resource getResourceById(@PathVariable int id) {
        return resourceService.getResourceById(id);
    }

    /**
     * 127.0.0.1/api/resources ---- post
     * {"currentPage":"1","pageSize":"5","orderBy":"id","direction":"desc","keyWord":""}
     */
    @PostMapping(value = "/resources", consumes = "application/json")
    public PageInfo<Resource> getResourcesBySearchBean(@RequestBody SearchBean searchBean) {
        return resourceService.getResourcesBySearchBean(searchBean);
    }

}
